//全局变量
var container = document.getElementById('container');

function createLawnMower(code) {
    let lawnmower = document.createElement('img');
    lawnmower.route = code;
	lawnmower.src = 'images/LawnMower.gif';
    lawnmower.style.position = 'absolute';
    lawnmower.style.top = code * 100 + 100 + 'px';
    lawnmower.style.left = 70 + 'px';
	lawnmower.style.width = '70px';
	lawnmower.style.height = '70px';
	lawnmower.speed = 0;
	lawnmower.style.zIndex = 25;
    lawnmower.step = ()=>{
        if(lawnmower.offsetLeft < 1000){
            lawnmower.style.left = lawnmower.offsetLeft + lawnmower.speed + 'px';
        }else{
			console.log(lawnmowers);
            lawnmowers = lawnmowers.filter(item=>item.route != lawnmower.route);
            container.removeChild(lawnmower);
			console.log(lawnmowers);
        }
    };
    container.appendChild(lawnmower);
	// lawnmowers.push(lawnmower);
    return lawnmower;
}
//常规植物位置
function generalPosition(peashooter,grass){

    var top = peashooter.offsetTop;
    var left = peashooter.offsetLeft;
    if (top < 0 || top >495 || left <= 130 || left > 850) {//草地之外
        //删除豌豆射手
        container.removeChild(peashooter);
        return;
    }
    if (top >= 0 && top <= 95 && left > 130 && left <= 210) {//第一格
        if (grass[0][0]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '160px';
            peashooter.route = 0;
            peashooter.columns = 0;
            grass[0][0]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }


    }else if (top >= 0 && top <= 95 && left > 210 && left <= 290) {
        if (grass[0][1]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '235px';
            peashooter.route = 0;
            peashooter.columns = 1;
            grass[0][1]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 290 && left <= 370) {
        if (grass[0][2]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '320px';
            peashooter.route = 0;
            peashooter.columns = 2;
            grass[0][2]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 370 && left <= 450) {
        if (grass[0][3]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '400px';
            peashooter.route = 0;
            peashooter.columns = 3;
            grass[0][3]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 450 && left <= 530) {
        if (grass[0][4]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '480px';
            peashooter.route = 0;
            peashooter.columns = 4;
            grass[0][4]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 530 && left <= 610) {
        if (grass[0][5]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '560px';
            peashooter.route = 0;
            peashooter.columns = 5;
            grass[0][5]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 610 && left <= 690) {
        if (grass[0][6]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '640px';
            peashooter.route = 0;
            peashooter.columns = 6;
            grass[0][6]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 690 && left <= 770) {
        if (grass[0][7]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '720px';
            peashooter.route = 0;
            peashooter.columns = 7;
            grass[0][7]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 770 && left <= 850) {
        if (grass[0][8]==0){
            peashooter.style.top = '90px';
            peashooter.style.left = '800px';
            peashooter.route = 0;
            peashooter.columns = 8;
            grass[0][8]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }
    else if (top > 95 && top <= 195 && left > 130 && left <= 210) {
        if (grass[1][0]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '160px';
            peashooter.route = 1;
            peashooter.columns = 0;
            grass[1][0]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 210 && left <= 290) {
        if (grass[1][1]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '235px';
            peashooter.route = 1;
            peashooter.columns = 1;
            grass[1][1]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 290 && left <= 370) {
        if (grass[1][2]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '320px';
            peashooter.route = 1;
            peashooter.columns = 2;
            grass[1][2]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 370 && left <= 450) {
        if (grass[1][3]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '400px';
            peashooter.route = 1;
            peashooter.columns = 3;
            grass[1][3]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 450 && left <= 530) {
        if (grass[1][4]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '480px';
            peashooter.route = 1;
            peashooter.columns = 4;
            grass[1][4]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 530 && left <= 610) {
        if (grass[1][5]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '560px';
            peashooter.route = 1;
            peashooter.columns = 5;
            grass[1][5]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 610 && left <= 690) {
        if (grass[1][6]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '640px';
            peashooter.route = 1;
            peashooter.columns = 6;
            grass[1][6]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 690 && left <= 770) {
        if (grass[1][7]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '720px';
            peashooter.route = 1;
            peashooter.columns = 7;
            grass[1][7]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 770 && left <= 850) {
        if (grass[1][8]==0){
            peashooter.style.top = '190px';
            peashooter.style.left = '800px';
            peashooter.route = 1;
            peashooter.columns = 8;
            grass[1][8]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }
    else if (top > 195 && top <= 295 && left > 130 && left <= 210) {
        if (grass[2][0]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '160px';
            peashooter.route = 2;
            peashooter.columns = 0;
            grass[2][0]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 210 && left <= 290) {
        if (grass[2][1]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '235px';
            peashooter.route = 2;
            peashooter.columns = 1;
            grass[2][1]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 290 && left <= 370) {
        if (grass[2][2]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '320px';
            peashooter.route = 2;
            peashooter.columns = 2;
            grass[2][2]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 370 && left <= 450) {
        if (grass[2][3]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '400px';
            peashooter.route = 2;
            peashooter.columns = 3;
            grass[2][3]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 450 && left <= 530) {
        if (grass[2][4]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '480px';
            peashooter.route = 2;
            peashooter.columns = 4;
            grass[2][4]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 530 && left <= 610) {
        if (grass[2][5]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '560px';
            peashooter.route = 2;
            peashooter.columns = 5;
            grass[2][5]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 610 && left <= 690) {
        if (grass[2][6]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '640px';
            peashooter.route = 2;
            peashooter.columns = 6;
            grass[2][6]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 690 && left <= 770) {
        if (grass[2][7]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '720px';
            peashooter.route = 2;
            peashooter.columns = 7;
            grass[2][7]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 770 && left <= 850) {
        if (grass[2][8]==0){
            peashooter.style.top = '290px';
            peashooter.style.left = '800px';
            peashooter.route = 2;
            peashooter.columns = 8;
            grass[2][8]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }
    else if (top > 295 && top <= 395 && left > 130 && left <= 210) {
        if (grass[3][0]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '160px';
            peashooter.route = 3;
            peashooter.columns = 0;
            grass[3][0]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 210 && left <= 290) {
        if (grass[3][1]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '235px';
            peashooter.route = 3;
            peashooter.columns = 1;
            grass[3][1]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 290 && left <= 370) {
        if (grass[3][2]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '320px';
            peashooter.route = 3;
            peashooter.columns = 2;
            grass[3][2]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 370 && left <= 450) {
        if (grass[3][3]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '400px';
            peashooter.route = 3;
            peashooter.columns = 3;
            grass[3][3]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 450 && left <= 530) {
        if (grass[3][4]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '480px';
            peashooter.route = 3;
            peashooter.columns = 4;
            grass[3][4]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 530 && left <= 610) {
        if (grass[3][5]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '560px';
            peashooter.route = 3;
            peashooter.columns = 5;
            grass[3][5]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 610 && left <= 690) {
        if (grass[3][6]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '640px';
            peashooter.route = 3;
            peashooter.columns = 6;
            grass[3][6]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 690 && left <= 770) {
        if (grass[3][7]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '720px';
            peashooter.route = 3;
            peashooter.columns = 7;
            grass[3][7]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 770 && left <= 850) {
        if (grass[3][8]==0){
            peashooter.style.top = '390px';
            peashooter.style.left = '800px';
            peashooter.route = 3;
            peashooter.columns = 8;
            grass[3][8]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }
    else if (top > 395 && top <= 495 && left > 130 && left <= 210) {
        if (grass[4][0]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '160px';
            peashooter.route = 4;
            peashooter.columns = 0;
            grass[4][0]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 210 && left <= 290) {
        if (grass[4][1]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '235px';
            peashooter.route = 4;
            peashooter.columns = 1;
            grass[4][1]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 290 && left <= 370) {
        if (grass[4][2]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '320px';
            peashooter.route = 4;
            peashooter.columns = 2;
            grass[4][2]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 370 && left <= 450) {
        if (grass[4][3]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '400px';
            peashooter.route = 4;
            peashooter.columns = 3;
            grass[4][3]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 450 && left <= 530) {
        if (grass[4][4]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '480px';
            peashooter.route = 4;
            peashooter.columns = 4;
            grass[4][4]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 530 && left <= 610) {
        if (grass[4][5]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '560px';
            peashooter.route = 4;
            peashooter.columns = 5;
            grass[4][5]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 610 && left <= 690) {
        if (grass[4][6]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '640px';
            peashooter.route = 4;
            peashooter.columns = 6;
            grass[4][6]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 690 && left <= 770) {
        if (grass[4][7]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '720px';
            peashooter.route = 4;
            peashooter.columns = 7;
            grass[4][7]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 770 && left <= 850) {
        if (grass[4][8]==0){
            peashooter.style.top = '490px';
            peashooter.style.left = '800px';
            peashooter.route = 4;
            peashooter.columns = 8;
            grass[4][8]=1;
            statement = true;
        }else {
            container.removeChild(peashooter);
            return;
        }

    }

}
function shovelPosition(shovel,grass){


    var top = shovel.offsetTop;
    var left = shovel.offsetLeft;
        if (top < 0 || top >495 || left <= 130 || left > 850) {//草地之外
            //删除豌豆射手
            container.removeChild(shovel);
            return;
        }
    if (top >= 0 && top <= 95 && left > 130 && left <= 210) {//第一格
        if (grass[0][0]==1){
            shovel.style.top = '90px';
            shovel.style.left = '160px';
            shovel.route = 0;
            shovel.columns = 0;
            grass[0][0]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }


    }else if (top >= 0 && top <= 95 && left > 210 && left <= 290) {
        if (grass[0][1]==1){
            shovel.style.top = '90px';
            shovel.style.left = '235px';
            shovel.route = 0;
            shovel.columns = 1;
            grass[0][1]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 290 && left <= 370) {
        if (grass[0][2]==1){
            shovel.style.top = '90px';
            shovel.style.left = '320px';
            shovel.route = 0;
            shovel.columns = 2;
            grass[0][2]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 370 && left <= 450) {
        if (grass[0][3]==1){
            shovel.style.top = '90px';
            shovel.style.left = '400px';
            shovel.route = 0;
            shovel.columns = 3;
            grass[0][3]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 450 && left <= 530) {
        if (grass[0][4]==1){
            shovel.style.top = '90px';
            shovel.style.left = '480px';
            shovel.route = 0;
            shovel.columns = 4;
            grass[0][4]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 530 && left <= 610) {
        if (grass[0][5]==1){
            shovel.style.top = '90px';
            shovel.style.left = '560px';
            shovel.route = 0;
            shovel.columns = 5;
            grass[0][5]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 610 && left <= 690) {
        if (grass[0][6]==1){
            shovel.style.top = '90px';
            shovel.style.left = '640px';
            shovel.route = 0;
            shovel.columns = 6;
            grass[0][6]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 690 && left <= 770) {
        if (grass[0][7]==1){
            shovel.style.top = '90px';
            shovel.style.left = '720px';
            shovel.route = 0;
            shovel.columns = 7;
            grass[0][7]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top >= 0 && top <= 95 && left > 770 && left <= 850) {
        if (grass[0][8]==1){
            shovel.style.top = '90px';
            shovel.style.left = '800px';
            shovel.route = 0;
            shovel.columns = 8;
            grass[0][8]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }
    else if (top > 95 && top <= 195 && left > 130 && left <= 210) {
        if (grass[1][0]==1){
            shovel.style.top = '190px';
            shovel.style.left = '160px';
            shovel.route = 1;
            shovel.columns = 0;
            grass[1][0]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 210 && left <= 290) {
        if (grass[1][1]==1){
            shovel.style.top = '190px';
            shovel.style.left = '235px';
            shovel.route = 1;
            shovel.columns = 1;
            grass[1][1]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 290 && left <= 370) {
        if (grass[1][2]==1){
            shovel.style.top = '190px';
            shovel.style.left = '320px';
            shovel.route = 1;
            shovel.columns = 2;
            grass[1][2]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 370 && left <= 450) {
        if (grass[1][3]==1){
            shovel.style.top = '190px';
            shovel.style.left = '400px';
            shovel.route = 1;
            shovel.columns = 3;
            grass[1][3]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 450 && left <= 530) {
        if (grass[1][4]==1){
            shovel.style.top = '190px';
            shovel.style.left = '480px';
            shovel.route = 1;
            shovel.columns = 4;
            grass[1][4]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 530 && left <= 610) {
        if (grass[1][5]==1){
            shovel.style.top = '190px';
            shovel.style.left = '560px';
            shovel.route = 1;
            shovel.columns = 5;
            grass[1][5]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 610 && left <= 690) {
        if (grass[1][6]==1){
            shovel.style.top = '190px';
            shovel.style.left = '640px';
            shovel.route = 1;
            shovel.columns = 6;
            grass[1][6]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 690 && left <= 770) {
        if (grass[1][7]==1){
            shovel.style.top = '190px';
            shovel.style.left = '720px';
            shovel.route = 1;
            shovel.columns = 7;
            grass[1][7]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 95 && top <= 195 && left > 770 && left <= 850) {
        if (grass[1][8]==1){
            shovel.style.top = '190px';
            shovel.style.left = '800px';
            shovel.route = 1;
            shovel.columns = 8;
            grass[1][8]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }
    else if (top > 195 && top <= 295 && left > 130 && left <= 210) {
        if (grass[2][0]==1){
            shovel.style.top = '290px';
            shovel.style.left = '160px';
            shovel.route = 2;
            shovel.columns = 0;
            grass[2][0]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 210 && left <= 290) {
        if (grass[2][1]==1){
            shovel.style.top = '290px';
            shovel.style.left = '235px';
            shovel.route = 2;
            shovel.columns = 1;
            grass[2][1]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 290 && left <= 370) {
        if (grass[2][2]==1){
            shovel.style.top = '290px';
            shovel.style.left = '320px';
            shovel.route = 2;
            shovel.columns = 2;
            grass[2][2]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 370 && left <= 450) {
        if (grass[2][3]==1){
            shovel.style.top = '290px';
            shovel.style.left = '400px';
            shovel.route = 2;
            shovel.columns = 3;
            grass[2][3]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 450 && left <= 530) {
        if (grass[2][4]==1){
            shovel.style.top = '290px';
            shovel.style.left = '480px';
            shovel.route = 2;
            shovel.columns = 4;
            grass[2][4]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 530 && left <= 610) {
        if (grass[2][5]==1){
            shovel.style.top = '290px';
            shovel.style.left = '560px';
            shovel.route = 2;
            shovel.columns = 5;
            grass[2][5]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 610 && left <= 690) {
        if (grass[2][6]==1){
            shovel.style.top = '290px';
            shovel.style.left = '640px';
            shovel.route = 2;
            shovel.columns = 6;
            grass[2][6]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 690 && left <= 770) {
        if (grass[2][7]==1){
            shovel.style.top = '290px';
            shovel.style.left = '720px';
            shovel.route = 2;
            shovel.columns = 7;
            grass[2][7]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 195 && top <= 295 && left > 770 && left <= 850) {
        if (grass[2][8]==1){
            shovel.style.top = '290px';
            shovel.style.left = '800px';
            shovel.route = 2;
            shovel.columns = 8;
            grass[2][8]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }
    else if (top > 295 && top <= 395 && left > 130 && left <= 210) {
        if (grass[3][0]==1){
            shovel.style.top = '390px';
            shovel.style.left = '160px';
            shovel.route = 3;
            shovel.columns = 0;
            grass[3][0]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 210 && left <= 290) {
        if (grass[3][1]==1){
            shovel.style.top = '390px';
            shovel.style.left = '235px';
            shovel.route = 3;
            shovel.columns = 1;
            grass[3][1]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 290 && left <= 370) {
        if (grass[3][2]==1){
            shovel.style.top = '390px';
            shovel.style.left = '320px';
            shovel.route = 3;
            shovel.columns = 2;
            grass[3][2]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 370 && left <= 450) {
        if (grass[3][3]==1){
            shovel.style.top = '390px';
            shovel.style.left = '400px';
            shovel.route = 3;
            shovel.columns = 3;
            grass[3][3]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 450 && left <= 530) {
        if (grass[3][4]==1){
            shovel.style.top = '390px';
            shovel.style.left = '480px';
            shovel.route = 3;
            shovel.columns = 4;
            grass[3][4]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 530 && left <= 610) {
        if (grass[3][5]==1){
            shovel.style.top = '390px';
            shovel.style.left = '560px';
            shovel.route = 3;
            shovel.columns = 5;
            grass[3][5]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 610 && left <= 690) {
        if (grass[3][6]==1){
            shovel.style.top = '390px';
            shovel.style.left = '640px';
            shovel.route = 3;
            shovel.columns = 6;
            grass[3][6]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 690 && left <= 770) {
        if (grass[3][7]==1){
            shovel.style.top = '390px';
            shovel.style.left = '720px';
            shovel.route = 3;
            shovel.columns = 7;
            grass[3][7]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 295 && top <= 395 && left > 770 && left <= 850) {
        if (grass[3][8]==1){
            shovel.style.top = '390px';
            shovel.style.left = '800px';
            shovel.route = 3;
            shovel.columns = 8;
            grass[3][8]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }
    else if (top > 395 && top <= 495 && left > 130 && left <= 210) {
        if (grass[4][0]==1){
            shovel.style.top = '490px';
            shovel.style.left = '160px';
            shovel.route = 4;
            shovel.columns = 0;
            grass[4][0]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 210 && left <= 290) {
        if (grass[4][1]==1){
            shovel.style.top = '490px';
            shovel.style.left = '235px';
            shovel.route = 4;
            shovel.columns = 1;
            grass[4][1]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 290 && left <= 370) {
        if (grass[4][2]==1){
            shovel.style.top = '490px';
            shovel.style.left = '320px';
            shovel.route = 4;
            shovel.columns = 2;
            grass[4][2]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 370 && left <= 450) {
        if (grass[4][3]==1){
            shovel.style.top = '490px';
            shovel.style.left = '400px';
            shovel.route = 4;
            shovel.columns = 3;
            grass[4][3]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 450 && left <= 530) {
        if (grass[4][4]==1){
            shovel.style.top = '490px';
            shovel.style.left = '480px';
            shovel.route = 4;
            shovel.columns = 4;
            grass[4][4]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 530 && left <= 610) {
        if (grass[4][5]==1){
            shovel.style.top = '490px';
            shovel.style.left = '560px';
            shovel.route = 4;
            shovel.columns = 5;
            grass[4][5]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 610 && left <= 690) {
        if (grass[4][6]==1){
            shovel.style.top = '490px';
            shovel.style.left = '640px';
            shovel.route = 4;
            shovel.columns = 6;
            grass[4][6]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 690 && left <= 770) {
        if (grass[4][7]==1){
            shovel.style.top = '490px';
            shovel.style.left = '720px';
            shovel.route = 4;
            shovel.columns = 7;
            grass[4][7]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }else if (top > 395 && top <= 495 && left > 770 && left <= 850) {
        if (grass[4][8]==1){
            shovel.style.top = '490px';
            shovel.style.left = '800px';
            shovel.route = 4;
            shovel.columns = 8;
            grass[4][8]=1;
            statement_chan = true;
        }else {
            container.removeChild(shovel);
            return;
        }

    }


}

//卡片跟随鼠标移动
function followMouse(plant){
    plant.attack = [];
    plant.style.position = 'absolute';
    //浏览器默认鼠标右键菜单
    document.oncontextmenu = e =>{
        e.preventDefault();//禁止默认效果
    };
    document.onmousemove = e =>{
        plant.style.top = e.y - 60 + 'px';
        plant.style.left = e.x - 60 + 'px';
    };
}

//创建射手精灵  onclick函数
function createPeashooter(type,onclick){
    var peashooter = document.createElement('img');
    peashooter.type = type;
    peashooter.style.top=0;
    if (type == 1){
        peashooter.src = 'images/Peashooter.gif';
        peashooter.score = 100;//普通射手消耗100太阳
        peashooter.style.left=0;
        peashooter.blood = 500;
    }else if (type == 2){
        peashooter.src = 'images/SnowPea.gif';
        peashooter.score = 175;
        peashooter.style.left=100+'px';
        peashooter.blood = 500;
    }else if (type == 3){
        peashooter.src = 'images/SunFlower.gif';
        peashooter.score = 50;
        peashooter.style.left=200+'px';
        peashooter.blood = 500;
    }else if (type == 4){
        peashooter.src = 'images/Repeater.gif';
        peashooter.score = 200;
        peashooter.style.left=300+'px';
        peashooter.blood = 500;
    }else if (type == 6){
        peashooter.src = 'images/GatlingPea.gif';
        peashooter.score = 450;
        peashooter.style.left=500+'px';
        peashooter.blood = 500;
    }else if (type == 7){
        peashooter.src = 'images/WallNut.gif';
        peashooter.score = 50;
        peashooter.style.left=600+'px';
        peashooter.blood = 3000;
    }

    //跟随鼠标移动
    followMouse(peashooter);
    document.onmousedown = e =>{
        document.onmousemove = null;//不在移动
        document.onmousedown = null;//不能二次种植
        if (e.button == 2){
            container.removeChild(peashooter);
        }else if (e.button == 0){
            generalPosition(peashooter,grass);

            if (statement) {//判断是否种下

                onclick(peashooter);
            }
        }
    };
    container.appendChild(peashooter);
    return peashooter;
}
//创建铲子
function createShovel(type,onclick){
    var shovel = document.createElement('img');
    shovel.type = type;
    shovel.style.top = 0;
    shovel.style.left = 780+'px';
    if (type == 0){
        shovel.src = 'images/Shovel.png';
    }
    followMouse(shovel);
    document.onmousedown = e =>{
        document.onmousemove = null;//不在移动
        document.onmousedown = null;//不能二次种植
        if (e.button == 2){
            container.removeChild(shovel);
        }else if (e.button == 0){
            shovelPosition(shovel,grass);
            // if (statement_chan == true) {
                onclick(shovel);
            // }

        }
    };
    container.appendChild(shovel);
    return shovel;
}

//创建爆炸精灵
function createBomb(type,onclick){//辣椒、樱桃、毁灭菇
    var bomb = document.createElement('img');
    bomb.type = type;
    bomb.style.top = 0;
    if (type == 5){//辣椒
        bomb.src = 'images/Jalapeno.gif';
        bomb.score = 100;
        bomb.blood = 500;
        bomb.style.left = 400+'px';
    }
    followMouse(bomb);//跟随鼠标移动
    document.onmousedown = e =>{
        document.onmousemove = null;//不在移动
        document.onmousedown = null;//不能二次种植
        if (e.button == 2){
            container.removeChild(bomb);
        }else if (e.button == 0){

            generalPosition(bomb,grass);
            if (statement == true) {
                onclick(bomb);
            }

        }
    };
    container.appendChild(bomb);
    return bomb;
}

//太阳精灵
function createSun(flower,code,disapper){
    var sun = document.createElement('img');
    sun.src = 'images/Sun.gif';
    sun.style.position = 'absolute';
    sun.style.top =flower.offsetTop + 'px';
    sun.style.left =flower.offsetLeft + 'px';
    sun.code = new Date().getTime() + 'sun' + code;
    sun.step = ()=>{//向上飞
        if (sun.offsetTop > -100){
            sun.style.top = sun.offsetTop - 4 + 'px';
        }else {
            disapper(sun);
        }

    };

    container.appendChild(sun);
    return sun;
}

//创建僵尸精灵
function createZombie(id,gameover){
    var zombie = document.createElement('img');
    zombie.style.position = 'absolute';
    //一共5条路，随机选一条   top[30,130,230,330,430]
    zombie.route = parseInt(Math.random()*5);
    tops = [30,130,230,330,430]
    zombie.style.top = tops[zombie.route]+'px';
    zombie.style.left = '900px';
    zombie.id = id;//给僵尸传入id
    zombie.status = parseInt(Math.random()*6);//0 1 2 3 4 5
    if ([0,1,2].indexOf(zombie.status) != -1){//普通僵尸概率1/2
        zombie.blood = 9;
        zombie.src = 'images/Zombie.gif';
    }else if (zombie.status == 5){//铁桶僵尸概率1/6
        zombie.src = 'images/BucketheadZombie.gif';
        zombie.blood = 49;
    }else{//路障僵尸1/3
        zombie.src = 'images/ConeheadZombie.gif';
        zombie.blood = 29;
    }
    zombie.counter = 0;//计数器
    zombie.speed = 2;//僵尸速度
    zombie.step = () =>{
        zombie.counter++;
        if (zombie.counter < 10){
            return;
        }
        zombie.counter = 0;//置0，计数器进入下一个周期
        //走路状态才能往前走且没有走进房子
        if (zombie.src.endsWith('Zombie.gif') && zombie.offsetLeft > -200){
            zombie.style.left = zombie.offsetLeft - zombie.speed + 'px';
        }
        //僵尸进入房子了
        if (zombie.offsetLeft < -150){
            gameover();
        }
    };
    container.appendChild(zombie);//僵尸放进容器
    return zombie;
}

//创建子弹
function createBullet(peashooter ,code ,disappear) {
    var bullet = document.createElement('img');
    bullet.route = peashooter.route;
    bullet.code = new Date().getTime() + 'bullet' + code;
    bullet.type = peashooter.type;
    if ([1,4].indexOf(bullet.type) >= 0){//豌豆射手（单双）
        bullet.src = 'images/Bullet.gif';
    }else if(bullet.type == 2){
        bullet.src = 'images/SnowBullet.gif';
    }else if (bullet.type == 6){
        bullet.src = 'images/Bullet.gif';
    }
    // else if(bullet.type == 3){
    //     bullet.src = 'images/Sun.gif';
    // }

    bullet.style.position = 'absolute';
    bullet.style.top = peashooter.offsetTop + 'px';
    bullet .style.left = peashooter.offsetLeft + 30 + 'px';
    bullet.step = ()=>{
        if(bullet.src.endsWith('Bullet.gif') &&
            bullet.offsetLeft < 1000){
            bullet.style.left = bullet.offsetLeft + 4 + 'px';
        }else{
            disappear(bullet);
        }

    };
    container.appendChild(bullet);
    return bullet;
}

//创建头
function createHead(zombie){
    var head = document.createElement('img');
    head.src = 'images/ZombieHead.gif';
    head.style.position = 'absolute';
    head.style.top = zombie.offsetTop - 40 + 'px';
    head.style.left = zombie.offsetLeft + 40 + 'px';
    container.appendChild(head);
    return head;
}